import React, { Component } from 'react';
import ThePagination from "@/components/ThePagination";
import { Form, Input, Select, Space, Button, Tabs } from "antd";
import { SearchOutlined } from "@ant-design/icons";
import KeepAlive, { AliveScope } from 'react-activation'
import TheTable from "@/components/TheTable";
import TheButton from "@/components/TheButton";
import Store from './components/store'
import Provide from './components/provide'
import Cate from './components/cate'
import Goods from './components/goods'
import store from "@/store/store"
import _connect from '@/_connect'

const { TabPane } = Tabs;
class Stock extends Component {
    constructor(props) {
        super(props)
        this.formRef = React.createRef()
        this.state = {
            columns: [
                {
                    title: "仓库名称",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                },
                {
                    title: "仓库负责人",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                },

                {
                    title: "联系方式",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                }, {
                    title: "操作",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return <div>
                            <TheButton haspermi={['storage:putIn:view']} onClick={() => this.props.history.push('/storageManager/outPut/add/123')}>查看详情</TheButton>
                            <TheButton haspermi={['storage:putIn:view']} >删除</TheButton>
                        </div>
                    }
                },
            ],
            dataSource: [],
            columnsCheck: [
                {
                    title: "盘点单号",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                },
                {
                    title: "盘点日期",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                },
                {
                    title: "仓库名称",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                },
                {
                    title: "盈亏量",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                },
                {
                    title: "登记人",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                },
                {
                    title: "审批人",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                },
                {
                    title: "审批时间",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                },
                {
                    title: "状态",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return text
                    }
                }, {
                    title: "操作",
                    dataIndex: "serviceShowFile",
                    key: "serviceShowFile",
                    render: (text, render) => {
                        return <div>
                            <TheButton haspermi={['storage:putIn:view']} onClick={() => this.props.history.push('/storageManager/outPut/add/123')}>查看详情</TheButton>
                            <TheButton haspermi={['storage:putIn:view']} >删除</TheButton>
                        </div>
                    }
                },
            ],
            dataSourceCheck: [],
            pageData: {
                pageNo: 1,
                pageSize: 10

            },
            pageDataCheck: {
                pageNo: 1,
                pageSize: 10

            },
            total: 0,
            tabs: [
                { label: '仓库管理', code: 'store', dom: Store },
                { label: '供应商管理', code: 'provide', dom: Provide },
                // { label: '物品分类', code: 'cate', dom: Cate },
                { label: '物品管理', code: 'goods', dom: Goods },

            ],
            defaultActiveKey: 'store'
        }
    }
    componentDidMount() {
        let allPermi = this.props.idents
        const tabs = this.state.tabs.filter(item => {
            if (allPermi.includes(`storage:store:${item.code}`)) {
                return item
            }
        })
        this.setState({
            tabs,
            defaultActiveKey: tabs.length > 0 && tabs[0].code
        })

        let searchParams = store.getState().pageTabValue
        if (searchParams) {
            let { tab } = searchParams
            this.setState({
                defaultActiveKey: tab
            })
        }
    }
    pageChange = (pageNo, pageSize) => {
        this.setState({
            pageData: {
                pageNo, pageSize
            }
        }, () => {
            this.getData()
        })
    };

    onChange(e) {
        let params = {
            tab: e
        }
        store.dispatch({
            type: 'SavePageTabValue',
            data: {
                ...params
            }
        })
        this.setState({
            defaultActiveKey: e
        })




    }
    render() {
        let { columns, dataSource, pageData, columnsCheck, total, tabs, defaultActiveKey } = this.state
        console.log(defaultActiveKey, 'defaultActiveKey');
        return (
            <div className="p-layout-box commodity-examine">
                <Tabs activeKey={defaultActiveKey} type="card" size={'small'} onChange={(e) => this.onChange(e)}>
                    {
                        tabs.map(item => {
                            return <TabPane key={item.code} tab={item.label}>

                                {<item.dom history={{ ...this.props.history }} />}

                            </TabPane>
                        })
                    }

                </Tabs>
            </div>
        );
    }
}
export default _connect(Stock)
